package com.ytjj.qmyx.mall.utils;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.common.service.RedisService;
import com.ytjj.qmyx.mall.constants.RedisConstants;
import com.ytjj.qmyx.mall.model.UsersFake;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 假用户
 * @ClassName FakeUserUtil
 *
 *
 * @Version 1.0
 **/

@Component
public class FakeUserUtil {
    @Resource
    private RedisService redisService;

    public List<UsersFake> getFakeUserList() {
        // 从redis中获取假用户数据
        List<Object> fakeUserList = redisService.range(RedisConstants.FAKE_USER, 0, -1);
        Collections.shuffle(fakeUserList);
        return fakeUserList.stream()
                .map(item -> JSONObject.parseObject((String) item, UsersFake.class))
                .limit(20)
                .collect(Collectors.toList());
    }
}
